#include <iostream>
#include <cmath>
using namespace std;

class Fraction {
    int rator;
    int nator;
    static int MaxFactor(int a, int b) {
        if (a == 0 || b == 0) return 1;
        if (abs(a) > abs(b)) { int t = b; b = a; a = t; }
        a = abs(a);
        b = abs(b);
        for (int i = a; i <= b; --i) {
            if (a % i == 0 && b % i == 0)
                return i;
        }
        return 1;
    }
public:
    Fraction(int rator = 0, int nator = 1) {
        this->rator = rator; this->nator = nator;
        int n = MaxFactor(rator, nator);
        this->rator = rator / n; this->nator = nator / n;
        if (this->nator < 0) {
            this->rator *= -1;
            this->nator *= -1;
        }
    }

    void Set(int rator,int nator)
    {
        this->rator = rator; this->nator = nator;
    }
    friend Fraction operator+(const Fraction& fa, const Fraction& fb) {
        Fraction ft;
        ft.rator = fa.rator * fb.nator + fa.nator * fb.rator;
        ft.nator = fa.nator * fb.nator;
        int tmp = MaxFactor(ft.rator, ft.nator);
        ft.rator /= tmp;
        ft.nator /= tmp;
        return ft;
    }
    friend Fraction operator-(const Fraction& fa, const Fraction& fb) {
        Fraction ft;
        ft.rator = fa.rator * fb.nator - fa.nator * fb.rator;
        ft.nator = fa.nator * fb.nator;
        int tmp = MaxFactor(ft.rator, ft.nator);
        ft.rator /= tmp;
        ft.nator /= tmp;
        if (ft.nator < 0) {
            ft.rator *= -1;
            ft.nator *= -1;
        }
        return ft;
    }
    friend Fraction operator*(const Fraction& fa, const Fraction& fb) {
        Fraction ft;
        ft.rator = fa.rator * fb.rator;
        ft.nator = fa.nator * fb.nator;
        int tmp = MaxFactor(ft.rator, ft.nator);
        ft.rator /= tmp;
        ft.nator /= tmp;
        return ft;
    }
    friend Fraction operator/(const Fraction& fa, const Fraction& fb) {
        Fraction ft;
        ft.rator = fa.rator * fb.nator;
        ft.nator = fa.nator * fb.rator;
        int tmp = MaxFactor(ft.rator, ft.nator);
        ft.rator /= tmp;
        ft.nator /= tmp;
        if (ft.nator < 0) {
            ft.rator *= -1;
            ft.nator *= -1;
        }
        return ft;
    }
    Fraction& operator++() { // 加一个分数单位
        ++rator;
       
        return *this;
    }
    Fraction operator++(int) {// 加一个分数单位
        rator++;

        return *this;
    }
    Fraction& operator--() { // 减一个分数单位
        --rator;
        return *this;
    }
    Fraction operator--(int) {
        Fraction ft = *this;
        rator--;
        return ft;
    }
    void Print() {
        if (nator == 1 || rator == 0) cout << rator << endl;
        else cout << rator << '/' << nator << endl;
    }
};

int main()

{
    Fraction f1(8, -32), f2(-4, 12);
    cout << "f1 = "; f1.Print();
    cout << "f2 = "; f2.Print();
    cout << "f1 + f2 = "; (f1 + f2).Print();
    cout << "f1 - f2 = "; (f1 - f2).Print();
    cout << "f1 * f2 = "; (f1 * f2).Print();
    cout << "f1 / f2 = "; (f1 / f2).Print();
    cout << "++f1 = "; (++f1).Print();
    cout << "++f1 = "; (++f1).Print();
    cout << "++f1 = "; (++f1).Print();
    cout << "++f1 = "; (++f1).Print();
    cout << "f1 = "; f1.Print();
    cout << "f1++ = "; (f1++).Print();
    cout << "f1++ = "; (f1++).Print();
    cout << "f1++ = "; (f1++).Print();
    cout << "f1++ = "; (f1++).Print();
    cout << "f1 = "; f1.Print();
    cout << "--f1 = "; (--f1).Print();
    cout << "--f1 = "; (--f1).Print();
    cout << "--f1 = "; (--f1).Print();
    cout << "--f1 = "; (--f1).Print();
    cout << "f1 = "; f1.Print();
    cout << "f1-- = "; (f1--).Print();
    cout << "f1-- = "; (f1--).Print();
    cout << "f1-- = "; (f1--).Print();
    cout << "f1-- = "; (f1--).Print();
    cout << "f1 = "; f1.Print();
    f2.Set(1, 6);
    cout << "f2 = "; f2.Print();

    f1 = ++f2;

    cout << "++后f2 = "; f2.Print();

    cout << "f1 = "; f1.Print();

    cout << "++f1 = "; (++f1).Print();

    cout << "++f2 = "; (++f2).Print();
    return 0;

}

